<%@ page import="com.neuedu.entity.User" %>
<%@ page import="java.sql.Array" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/11/9
  Time: 14:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <style>
        .last{
            background: gray;
            font-weight: 900;
        }

        .odd{
            background: aqua;
        }
        .even{
            background: burlywood;
        }

    </style>
</head>
<body>

<%--    输出一段内容 --%>
<%
   //模拟调用Controller
    List<User> userList = new ArrayList<User>();
    for (int i = 0; i < 10; i++) {
        userList.add(new User("admin"+i,"12456"+i,"nickname"+i));
    }
    request.setAttribute("userList",userList);


%>


渲染表格
<table border="1" width="100%"  cellpadding="0" cellspacing="0">
    <tr align="center">
        <td>序号</td>
        <td>username</td>
        <td>password</td>
        <td>nickname</td>
    </tr>

<%--
    items:  遍历的集合  ArrayList
    var :   遍历获取到的每一个元素
    varStatus: 遍历获取到的每一个元素的状态(int:index、 Int： count        boolean：first last...)

  begin="3" end="5"  --%>
    <c:forEach items="${userList}"  var="user"  varStatus="stats" >
        <tr align="center"
            <c:choose>
                 <c:when test="${stats.count%2==0}"> class="odd"</c:when>
                  <c:otherwise>class="even"</c:otherwise>

            </c:choose>

        >

            <td>${stats.index}  --   ${stats.count}</td>
            <td>${user.username}</td>
            <td>${user.password}</td>
            <td>${user.nickname}</td>
        </tr>
    </c:forEach>
</table>

<hr>
<table border="1" width="100%"  cellpadding="0" cellspacing="0">
    <tr align="center">
        <td>序号</td>
        <td>username</td>
        <td>password</td>
        <td>nickname</td>
    </tr>

    <%--     begin="3" end="5"  --%>
    <c:forEach items="${userList}"  var="user"   step="3" varStatus="stats" >
        <tr align="center"
                <c:if test="${stats.last}"> class="last"</c:if>

        >

            <td>${stats.index}  --   ${stats.count}</td>
            <td>${user.username}</td>
            <td>${user.password}</td>
            <td>${user.nickname}</td>
        </tr>
    </c:forEach>
</table>





</body>
</html>
